// pages/funcs/factoryRegister/factoryRegister.js
var app = getApp();
import {
    areaList
} from '@vant/area-data';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        factoryName: '',
        areaList, //城市地区数据
        show: false, //控制弹出层出现
        area: '',
        address: '',
        bussinessScope: '',
        isInPark: '',
        socialId: '',
        workerNum: '',
        mainProduct: '',
        mainChemistry: '',
        structureArea: '',
        chemistryArea: '',
        containerArea: '',
        emergencyPhone: '',
        securityPhone: ''
    },
    //展示地区选择器弹出层
    showPopup() {
        this.setData({
            show: true
        });
    },
    //关闭地区选择器弹出层
    onClose() {
        this.setData({
            show: false
        });
    },
    //选择地区完成后的格式化工作
    onConfirm(result) {
        var address = result.detail.values;
        var addressShow = address[0].name + '/' + address[1].name + '/' + address[2].name;
        this.setData({
            area: addressShow
        })
        this.onClose();
    },
    //是否在化工园区单选框的选择事件
    radioChange(event) {
        this.setData({
            isInPark: event.detail
        });
    },
    //检查表单内容是否非空
    checkNull(data) {
        for (var key in data) {
            if (data[key] == false&&key!='show') {
                return false;
            }
        }
        return true;
    },
    //提交函数
    OnSubmit() {
        var data = this.data;
        if (!this.checkNull(data)) {
            wx.showToast({
                title: '请完整填写表单信息',
                icon: 'error'
            })
        } else {
            wx.showLoading({
                title: '提交中...',
                mask:true
              });
            wx.request({
                url: app.globalData.ipAddress+'/abc',
                method: 'POST',
                data: {
                    factoryName:this.data.factoryName,
                    area:this.data.area,
                    address:this.data.address,
                    bussinessScope:this.data.bussinessScope,
                    isInPark:this.data.isInPark,
                    socialId:this.data.socialId,
                    workerNum:this.data.workerNum,
                    mainProduct:this.data.mainProduct,
                    mainChemistry:this.data.mainChemistry,
                    structureArea:this.data.structureArea,
                    chemistryArea:this.data.chemistryArea,
                    containerArea:this.data.containerArea,
                    emergencyPhone:this.data.emergencyPhone,
                    securityPhone:this.data.securityPhone
                },
                success(res){
                    wx.hideLoading({
                        success:(res)=>{}
                    })
                },
                fail(res){
                    // wx.hideLoading({
                    //     success:(res)=>{}
                    // })
                }
            });
        }

    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        //加载时动态修改导航栏标题
        wx.setNavigationBarTitle({
            title: '企业登记'
        })

    }
})